package main

import "fmt"

func main() {
	fmt.Println(cuttingRope(18))
	fmt.Println(cuttingRope(1))
}

func cuttingRope(n int) int {
  if n < 2 { panic("rope must > 2") }
	temp := 0
	dp := make([]int, n+1)
	for i := 2; i <= n; i++ {
		for j := 1; j < i; j++ {
			if j*(i-j) < j*dp[i-j] {
				temp = j * dp[i-j]
			} else {
				temp = j * (i - j)
			}
			if temp > dp[i] {
				dp[i] = temp
			}
		}
	}
	return dp[n]
}
